<?php
import ( 'ORG.Util.Input' );
import('@.ORG.FAC');
class SystemSettingsModel extends Think{
	/**
	 * 
	 * 修改配置信息
	 * @param array $data
	 */
	function changeBaseSettings(Array $data){
		$_data['URL_HTML_SUFFIX'] = FAC::F($data['url_html_suffix'] , FAC::URL_SUFFIX);
		$_data['URL_MODEL'] = FAC::F($data['url_model'] , FAC::INT);
		$_data['FR_LINKIMAGE_WIDTH'] = FAC::F($data['fr_linkimage_width'] , FAC::INT);
		$_data['FR_LINKIMAGE_HEIGHT'] = FAC::F($data['fr_linkimage_height'] , FAC::INT);
		$_data['DEFAULT_LANG'] = FAC::F($data['default_lang'] , FAC::STRING);
		$_data['LANG_AUTO_DETECT'] = FAC::F($data['lang_auto_detect'] , FAC::BOOL_VALUE);
		$_data['SMS_ON'] = FAC::F($data['sms_on'] , FAC::BOOL_VALUE);
		$_data['SMS_MOBILE'] = FAC::F($data['sms_mobile'] , FAC::TEL);
		$_data['LOG_ADMIN']	= FAC::F($data['log_admin'], FAC::BOOL_VALUE);
		
		return $this->writeToConfigFile($_data, __ROOT__.'/Conf/base.config.php');
	}
	/**
	 * 修改个性化配置
	 * Enter description here ...
	 * @param array $data
	 */
	function changeCustomizationSettings(Array $data){
		$_data['URL_HTML_SUFFIX'] = FAC::F($data['url_html_suffix'] , FAC::URL_SUFFIX);
		$_data['URL_MODEL'] = FAC::F($data['url_model'] , FAC::INT);
		$_data['DEFAULT_LANG'] = FAC::F($data['default_lang'] , FAC::STRING);
		$_data['LANG_AUTO_DETECT'] = FAC::F($data['lang_auto_detect'] , FAC::BOOL_VALUE);
		$_data['DEFAULT_THEME'] = FAC::F($data['default_theme'], FAC::STRING);
		$_data['GUESTBOOK_NEED_AUDIT']	=	FAC::F($data['guestbook_need_audit'] , FAC::INT);
		return $this->writeToConfigFile($_data, __ROOT__.'/Conf/customization.config.php');
	}
	
	private function writeToConfigFile($configs, $file){
		$config = require($file);
		$config = array_merge($config , $configs);
		$string_start   = "<?php\n return ";
		$string_process = var_export($config, TRUE);
		$string_end     = "\n?>";
		$string         = $string_start.$string_process.$string_end;
		
		if(file_put_contents('.'.$file, $string) > 0){
   			return true;
		}else{
			return false;
		}
	}

}